<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
         <p:panel id="panel" header="View Sale Orders"> 
                <p:ajaxStatus style="width:16px;height:16px;">   
                    <f:facet name="start">   
                        <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                    </f:facet> 
 
                <f:facet name="complete">   
                        <h:outputText value="" />   
                    </f:facet>   
                </p:ajaxStatus>
            <h:form prependId="false">
                <p:messages/>
                <p:dataTable var="saleOrder" value="#{viewAllSaleOrder.saleOrders}"
                         selection="#{viewAllSaleOrder.selectedSaleOrder}" dynamic="true" paginator="true" rows="5" emptyMessage="No sale order"> 
          
                <p:column selectionMode="single" />
                
                <p:column sortBy="#{saleOrder.id}" filterBy="#{saleOrder.id}"> 
                    <f:facet name="header"> 
                        <h:outputText value="ID" /> 
                    </f:facet> 
                    <h:outputText value="#{saleOrder.id}" /> 
                </p:column> 

                <p:column sortBy="#{saleOrder.customer.saleLeadName}" filterBy="#{saleOrder.customer.saleLeadName}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Customer Name" /> 
                    </f:facet> 
                    <h:outputText value="#{saleOrder.customer.saleLeadName}" /> 
                </p:column>

                
                <p:column sortBy="#{saleOrder.customer.registrationNumber}" filterBy="#{saleOrder.customer.registrationNumber}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Registration Number" /> 
                    </f:facet> 
                    <h:outputText value="#{saleOrder.customer.registrationNumber}" /> 
                </p:column> 
                
                <p:column sortBy="#{saleOrder.stateSaleOrder}" filterBy="#{saleOrder.stateSaleOrder}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Status" /> 
                    </f:facet> 
                    <h:outputText value="#{saleOrder.stateSaleOrder}" /> 
                </p:column> 
                

                <f:facet name="footer">                   
                    <p:commandButton value="View" image="ui-icon ui-icon-search" update="display1 display2" oncomplete="saleOrderViewDialog.show()"/>
                    <p:commandButton value="Edit" actionListener="#{viewAllSaleOrder.editSaleOrder}"/>
                    <p:commandButton value="Delete" image="ui-icon ui-icon-trash" onclick="saleOrderDeleteDialog1.show()">
                        <f:setPropertyActionListener value="#{saleOrder}" target="#{viewAllSaleOrder.selectedSaleOrder}"/>
                    </p:commandButton>
                    <p:commandButton value="Check Credit" actionListener="#{viewAllSaleOrder.checkCredit}" update="panel"/>                    
                    <p:commandButton value="Check ATP" actionListener="#{viewAllSaleOrder.checkCredit}" update="panel"/>
                    <p:commandButton value="Confirm Order" actionListener="#{viewAllSaleOrder.confirmOrder}" update="panel"/>
                    
                </f:facet>
                
                
            </p:dataTable>
                
                <p:confirmDialog message="Are you sure to delete the sale order?"  
        showEffect="clip" hideEffect="fold" 
        header="Initiating delete process" severity="alert" widgetVar="saleOrderDeleteDialog1">  

                <p:commandButton value="Yes" update="messages" oncomplete="saleOrderDeleteDialog1.hide()"  
                            actionListener="#{viewAllSaleOrder.deleteSaleOrder}" />  
                <p:commandButton value="No" onclick="saleOrderDeleteDialog1.hide()" type="button" />   

            </p:confirmDialog>  
                    
            
            <p:dialog header="Sale Order Detail" widgetVar="saleOrderViewDialog" width="400" height="400" resizable="true" showEffect="clip" hideEffect="fold">
                <h:panelGrid id="display1" columns="2" cellpadding="4">
                    
                    <h:outputText value="SaleOrder ID:"/>
                    <h:outputText value="#{viewAllSaleOrder.selectedSaleOrder.id}"/>
                    
                    <h:outputText value="Date:"/>
                    <h:outputText value="#{viewAllSaleOrder.selectedSaleOrder.saleOrderDate}"/>
                    
                    <h:outputText value="Customer ID:"/>
                    <h:outputText value="#{viewAllSaleOrder.selectedSaleOrder.customer.registrationNumber}"/>
                    
                    <h:outputText value="Customer Name:"/>
                    <h:outputText value="#{viewAllSaleOrder.selectedSaleOrder.customer.saleLeadName}"/>
                
                </h:panelGrid>
                
                <p:dataTable var="lineItem" value="#{viewAllSaleOrder.selectedSaleOrder.lineItems}"
                             dynamic="true" paginator="true" emptyMessage="No Product Type" id="display2">
                    <p:column sortBy="#{lineItem.productPrice.productType}">
                        <f:facet name="header">
                            <h:outputText value="Product Type"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.productPrice.productType}"/>
                    </p:column>
                        
                    <p:column sortBy="#{lineItem.lineItemQuantity}">
                        <f:facet name="header">
                            <h:outputText value="Quantity"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.lineItemQuantity}"/>
                    </p:column>
                    
                    <p:column sortBy="#{lineItem.productPrice.productPrice}">
                        <f:facet name="header">
                            <h:outputText value="Price"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.productPrice.productPrice}"/>
                    </p:column>
                    <f:facet name="footer">
                        <h:outputText value="Total Price: "/>
                        <h:outputText value="#{viewAllSaleOrder.selectedSaleOrder.totalPrice}"/>                        
                    </f:facet>
                 </p:dataTable>
   
            </p:dialog>
        </h:form>
     </p:panel>
    </ui:define>

</ui:composition>
